<?php
    include("header.php");
    setTabIndex(3);
    createPage("Liga - Links");
    if (isset($_SESSION['user'])) $user = $_SESSION['user'];
?>

<table height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0" bgcolor="#FFFFFF">

    <tr>

        <td id="leftFiller" valign="top" height="100%" rowspan="3" bgcolor="#666666">

            <table border="0" cellpadding="0" cellspacing="0" height="100%" width="8px">

                <tr><td>&nbsp;</td></tr>

            </table>

        </td>

        <td id="header" valign="top" width="100%">

            <table border="0" width="100%" cellpadding="3" cellspacing="0" bgcolor="#10425b">
                <tr>
                    <td bgcolor="#666666" width="70%">
                        <?php include("inc_title.html"); ?>
                    </td>
                    <td bgcolor="#666666" align="right" valign="top">&nbsp;

                    </td>
                </tr>
            </table>
            <table align="center" border="0" width="100%" height="90%" cellpadding="0" cellspacing="0" style="border-top:#BCDD10 4px solid;">
                <tr>
                    <?php include("inc_sublinks.php"); ?>   
                </tr>

                <tr>

                    <td colspan="2" nowrap bgcolor="#BCDD10" height="4"><img src="../assets/images/spacer.gif" alt="" height="1" width="1"></td>

                </tr>

                <tr>

                    <td>&nbsp;</td>

                    <td valign="top">

                        <table align="center" cellspacing="0" cellpadding="1" width="95%">

                            <tr>

                                <td colspan="4"><em>Tip: u ziet extra informatie als u met de muis over

                                de link gaat !</em></td>

                                <br/>

                            </tr>

                            <tr>

                                <td width="25%"><span class="blackHeaderLarge">Algemeen</span></td>

                                <td width="30%"><span class="blackHeaderLarge">Club</span></td>

                                <td width="25%"><span class="blackHeaderLarge">Organisatie</span></td>

                                <td width="20%"><span class="blackHeaderLarge">Blog</span></td>

                            </tr>

                        <?php

                            $result = mysql_query("select l.linkId, lc.categoryName, l.clubId, l.linkName,

                                l.linkUrl, l.linkNote from link l join link_category lc on l.linkCategoryId = lc.linkCategoryId

                                order by lc.linkCategoryId, l.linkName");



                            $generalLinkItems = array();

                            $clubLinkItems = array();

                            $blogLinkItems = array();

                            $organisationLinkItems = array();

                            while ($row = mysql_fetch_assoc($result)) {

                                if (!isset($linkId) || $linkId != $row['linkId']) {

                                    $linkId = $row['linkId'];

                                    $linkItem = new LinkItem;

                                    $linkItem->link_id = $linkId;

                                    $linkItem->club_id = $row['clubId'];

                                    $linkItem->link_category = $row['categoryName'];

                                    $linkItem->link_name = $row['linkName'];

                                    $linkItem->link_url = $row['linkUrl'];

                                    $linkItem->link_note = $row['linkNote'];

                                    if (strnatcasecmp($linkItem->link_category, 'Algemeen') == 0) {

                                        array_push($generalLinkItems, $linkItem);

                                    } else if (strnatcasecmp($linkItem->link_category, 'Club') == 0) {

                                        array_push($clubLinkItems, $linkItem);

                                    } else if (strnatcasecmp($linkItem->link_category, 'Organisatie') == 0) {

                                        array_push($blogLinkItems, $linkItem);

                                    } else if (strnatcasecmp($linkItem->link_category, 'Blog') == 0) {

                                        array_push($organisationLinkItems, $linkItem);

                                    }

                                }

                            }



                            $result = mysql_query("select club_id, clubname, website from club where

                                clubname <> '' and website like 'http://%' order by club_id");

                            $clubItems = array();

                            while ($row = mysql_fetch_assoc($result)) {

                                if (!isset($clubId) || $clubId != $row['club_id']) {

                                    $clubId = $row['club_id'];

                                    $clubItem = new ClubItem;

                                    $clubItem->club_id = $clubId;

                                    $clubItem->clubname = $row['clubname'];

                                    $clubItem->website = $row['website'];

                                    array_push($clubItems, $clubItem);

                                }

                            }



                            $generalCount = count($generalLinkItems);

                            $clubCount = count($clubLinkItems);

                            $blogCount = count($blogLinkItems);

                            $organisationCount = count($organisationLinkItems);

                            $count = $generalCount;

                            if ($clubCount > $count) {

                                $count = $clubCount;

                            } else if ($blogCount > $count) {

                                $count = $blogCount;

                            } else if ($organisationCount > $count) {

                                $count = $organisationCount;

                            }



                            for ($i = 1; $i <= $count; $i++) {

                        ?>

                            <tr>

                                <td valign="top" class="link">

                        <?php

                                if ($i <= $generalCount) {

                                    if ($i == 1) {

                                        $generalLink = current($generalLinkItems);

                                    } else {

                                        $generalLink = next($generalLinkItems);

                                    }



                                    if (isset($user) && $user->club_id=100) {

                        ?>

                                    <a href="edit_link_form.php?linkId=<?=$generalLink->link_id?>"><img src="../assets/images/16x16/shadow/document.gif" border="0"></a>

                        <?php

                                    }



                                    $linkId = "generalLink_".$i;

                        ?>

                                    <a id="<?=$linkId?>" target="_blank" href="<?=$generalLink->link_url?>"><?=$generalLink->link_name?></a>

                        <?php

                                    if ( !empty($generalLink->link_note) ) {

                                        $caption = $generalLink->link_note;

                        ?>

                                    <span dojoType="dijit.Tooltip" connectId="<?=$linkId?>"><?=$caption?></span>

                        <?php

                                    }

                                }

                        ?>

                                </td>

                                <td valign="top" class="link">

                        <?php

                                if ($i <= $clubCount) {

                                    if ($i == 1) {

                                        $clubLink = current($clubLinkItems);

                                    } else {

                                        $clubLink = next($clubLinkItems);

                                    }



                                    if (isset($user) && $user->club_id=100) {

                        ?>

                                    <a href="edit_link_form.php?linkId=<?=$clubLink->link_id?>"><img src="../assets/images/16x16/shadow/document.gif" border="0"></a>

                        <?php

                                    }



                                    if ( empty($clubLink->club_id) ) {

                                        $linkId = "clubLink_".$i;

                            ?>

                                        <a id="<?=$linkId?>" target="_blank" href="<?=$clubLink->link_url?>"><?=$clubLink->link_name?></a>

                            <?php

                                    } else {

                                        foreach ($clubItems as $clubitem) {

                                            if ($clubLink->club_id == $clubitem->club_id) {

                                                    $linkId = "clubLink_".$clubLink->club_id;

                            ?>

                                                <a id="<?=$linkId?>" target="_blank" href="<?=$clubitem->website?>"><?=$clubitem->clubname?></a>

                            <?php

                                                break;

                                            }

                                        }

                                    }



                                    if ( !empty($clubLink->link_note) ) {

                                            $caption = $clubLink->link_note;

                            ?>

                                                <span dojoType="dijit.Tooltip" connectId="<?=$linkId?>"><?=$caption?></span>

                            <?php

                                    }

                                }

                        ?>

                                </td>

                                <td valign="top" class="link">

                        <?php

                                if ($i <= $blogCount) {

                                    if ($i == 1) {

                                        $blogLink = current($blogLinkItems);

                                    } else {

                                        $blogLink = next($blogLinkItems);

                                    }



                                    if (isset($user) && $user->club_id=100) {

                        ?>

                                    <a href="edit_link_form.php?linkId=<?=$blogLink->link_id?>"><img src="../assets/images/16x16/shadow/document.gif" border="0"></a>

                        <?php

                                    }



                                    $linkId = "blogLink_".$i;

                        ?>

                                    <a id="<?=$linkId?>" target="_blank" href="<?=$blogLink->link_url?>"><?=$blogLink->link_name?></a>

                        <?php

                                    if ( !empty($blogLink->link_note) ) {

                                        $caption = $blogLink->link_note;

                        ?>

                                    <span dojoType="dijit.Tooltip" connectId="<?=$linkId?>"><?=$caption?></span>

                        <?php

                                    }

                                }

                        ?>

                                </td>

                                <td valign="top" class="link">

                        <?php

                                if ($i <= $organisationCount) {

                                    if ($i == 1) {

                                        $organisationLink = current($organisationLinkItems);

                                    } else {

                                        $organisationLink = next($organisationLinkItems);

                                    }



                                    if (isset($user) && $user->club_id=100) {

                        ?>

                                    <a href="edit_link_form.php?linkId=<?=$organisationLink->link_id?>"><img src="../assets/images/16x16/shadow/document.gif" border="0"></a>

                        <?php

                                    }



                                    $linkId = "organisationLink_".$i;

                        ?>

                                    <a id="<?=$linkId?>" target="_blank" href="<?=$organisationLink->link_url?>"><?=$organisationLink->link_name?></a>

                        <?php

                                    if ( !empty($organisationLink->link_note) ) {

                                        $caption = $organisationLink->link_note;

                        ?>

                                    <span dojoType="dijit.Tooltip" connectId="<?=$linkId?>"><?=$caption?></span>

                        <?php

                                    }

                                }

                        ?>

                                </td>

                            <tr>

                        <?php

                            }

                        ?>

                            </tr>

                        </table>

                    </td>

                </tr>

            </table>

        </td>

    </tr>

</table>



</body>

</html>

